package com.atguigu.tingshu.user.client;

import com.atguigu.tingshu.common.cache.GuiguCache;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.user.service.VipServiceConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author GQS @Date 2024/11/5/21:40 @Description
 * 用户信息内部调用的控制层
 */
@RestController
@RequestMapping(value = "/client/user/userInfo")
public class UserInfoClientController {

  @Autowired
  private UserInfoService userInfoService;

  /**
   * 查询用户的信息
   * @param userId
   * @return
   */
  // @GuiguCache(name = "getUserInfo")
  @GetMapping(value = "/getUserInfo/{userId}")
  public UserInfo getUserInfo(@PathVariable(value = "userId") Long userId){
    return userInfoService.getById(userId);
  }

  /**
   * 查询用户是否购买过专辑的记录
   * @param userId
   * @param albumId
   * @return
   */
  @GetMapping("/getUserPaidAlbum/{userId}/{albumId}")
  public Boolean getUserPaidAlbum(@PathVariable("userId") Long userId, @PathVariable("albumId") Long albumId){
    return userInfoService.getUserPaidAlbum(userId, albumId);
  }

  /**
   * 查询用户在某专辑中购买过声音的记录
   * @param userId
   * @param albumId
   * @return
   */
  @GetMapping("/getUserPaidTrack/{userId}/{albumId}")
  public Map<String, Object> getUserPaidTrack(@PathVariable("userId") Long userId, @PathVariable("albumId") Long albumId){
    return userInfoService.getUserPaidTrack(userId, albumId);
  }

  @Autowired
  private VipServiceConfigService vipServiceConfigService;

  /**
   * 查询VIP服务的详细信息
   * @param id
   * @return
   */
  @GetMapping("getUserVipService/{id}")
  public VipServiceConfig getVipServiceConfig(@PathVariable(value = "id") Long id){
    return vipServiceConfigService.getById(id);
  }
}
